package com.mankiw.insight.spring.web;

import com.mankiw.insight.spring.Component;

@Component
@Controller
@RequestMapping("/hello")
public class HelloController {
    @RequestMapping("/a")
    public String hello(@Param("name") String name, @Param("age") Integer age) {
        return "hello world " + name + " " + age;
    }

    @RequestMapping("/json")
    @ResponseBody
    public User json(@Param("name") String name, @Param("age") Integer age) {
        User user = new User();
        user.setAge(age);
        user.setName(name);
        return user;
    }

    @RequestMapping("/html")
    public ModelAndView html(@Param("name") String name, @Param("age") Integer age) {
        ModelAndView mav = new ModelAndView();
        mav.getContext().put("name",name);
        mav.getContext().put("age",age.toString());
        mav.setView("index.html");
        return mav;
    }
}
